#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#if 0
#include <stack>

void TestStack()
{
    stack<int> s;
    s.push(1);
    s.push(2);
    s.push(3);
    s.push(4);
    s.push(5);
    s.push(6);
    cout << s.top() << endl;
    cout << s.size() << endl;

    s.pop();
    s.pop();
    s.pop();
    cout << s.top() << endl;
    cout << s.size() << endl;
}
#endif

#if 0
#include "Stack.h"

void TestStack()
{
    bite::stack<int> s;
    s.push(1);
    s.push(2);
    s.push(3);
    s.push(4);
    s.push(5);
    s.push(6);
    cout << s.top() << endl;
    cout << s.size() << endl;

    s.pop();
    s.pop();
    s.pop();
    cout << s.top() << endl;
    cout << s.size() << endl;
}

int main()
{
    TestStack();
    return 0;
}
#endif


#if 0
//#include <queue>
#include "Queue.h"

int main()
{
    bite::queue<int> q;
    q.push(1);
    q.push(2);
    q.push(3);
    q.push(4);
    q.push(5);
    q.push(6);
    cout << q.size() << endl;
    cout << q.front() << endl;
    cout << q.back() << endl;

    q.pop();
    q.pop();
    q.pop();
    cout << q.size() << endl;
    cout << q.front() << endl;
    cout << q.back() << endl;
    return 0;
}
#endif

#if 0
#include <queue>

void TestPriorityQueue1()
{
    // 默认按照less方式比较，创建的是大堆
    priority_queue<int> q;
    q.push(5);
    q.push(4);
    q.push(8);
    q.push(1);
    q.push(9);
    q.push(2);
    q.push(6);
    q.push(3);
    q.push(7);
    q.push(0);
    cout << q.size() << endl;
    cout << q.top() << endl;

    q.pop();
    q.pop();
    q.pop();
    cout << q.size() << endl;
    cout << q.top() << endl;
}


// greater是STL提供的以大于方式比较两个元素的类模板
// 在使用时一定要<functional>的头文件
void TestPriorityQueue2()
{
    // 如果要创建小堆，则元素必须按照大于的方式比较
    priority_queue<int,vector<int>, greater<int>> q;
    q.push(5);
    q.push(4);
    q.push(8);
    q.push(1);
    q.push(9);
    q.push(2);
    q.push(6);
    q.push(3);
    q.push(7);
    q.push(0);
    cout << q.size() << endl;
    cout << q.top() << endl;

    q.pop();
    q.pop();
    q.pop();
    cout << q.size() << endl;
    cout << q.top() << endl;
}

class Date
{
public:
    Date(int year, int month, int day)
        : _year(year)
        , _month(month)
        , _day(day)
    {}

    bool operator<(const Date& d)const
    {
        return _day < d._day;
    }

    bool operator>(const Date& d)const
    {
        return _day > d._day;
    }

    friend bool CompareDate(const Date* left, const Date* right);
    friend class Compare;
private:
    int _year;
    int _month;
    int _day;
};

void TestPriorityQueue3()
{
    priority_queue<Date> q;

    Date d1(2023, 4, 22);
    Date d2(2023, 4, 21);
    Date d3(2023, 4, 23);

    q.push(d1);
    q.push(d2);
    q.push(d3);
}

void TestPriorityQueue5()
{
    vector<int> v{ 3,2,7,6,0,4,1,9,8,5 };
    priority_queue<int> q(v.begin(), v.end());
}

void TestPriorityQueue4()
{
    priority_queue<Date, vector<Date>, greater<Date>> q;

    Date d1(2023, 4, 22);
    Date d2(2023, 4, 21);
    Date d3(2023, 4, 23);

    q.push(d1);
    q.push(d2);
    q.push(d3);
}


bool CompareDate(const Date* left, const Date* right)
{
    return left->_day < right->_day;
}

typedef bool (*COM)(const Date* left, const Date* right);

void TestPriorityQueue6()
{
    priority_queue<Date*, vector<Date*>, COM> q(CompareDate);

    Date d1(2023, 4, 22);
    Date d2(2023, 4, 21);
    Date d3(2023, 4, 23);

    q.push(&d1);
    q.push(&d2);
    q.push(&d3);
}

// 仿函数--函数对象：可以像函数一样使用的对象
class Compare
{
public:
    bool operator()(const Date* left, const Date* right)
    {
        return left->_day < right->_day;
    }
};

void TestPriorityQueue7()
{
    Date d1(2023, 4, 22);
    Date d2(2023, 4, 21);
    Date d3(2023, 4, 23);

    CompareDate(&d1, &d2);
    Compare com;
    com(&d1, &d2);
    com.operator()(&d1, &d2);

    priority_queue<Date*, vector<Date*>, Compare> q;
    q.push(&d1);
    q.push(&d2);
    q.push(&d3);
}

int main()
{
    // TestPriorityQueue1();
    // TestPriorityQueue2();
    // TestPriorityQueue3();
    // TestPriorityQueue6();
    TestPriorityQueue7();
    return 0;
}
#endif


//void TestPriorityQueue1()
//{
//    vector<int> v{ 3,2,7,6,0,4,1,9,8,5 };
//    priority_queue<int, vector<int>, Greater<int>> q(v.begin(), v.end());
//}

void TestPriorityQueue2() {
    vector<int> v{3, 2, 7, 6, 0, 4, 1, 9, 8, 5};
    priority_queue<int> q;
    for (auto e: v) {
        q.push(e);
    }

    cout << q.size() << endl;
    cout << q.top() << endl;

    q.pop();
    q.pop();
    q.pop();
    cout << q.size() << endl;
    cout << q.top() << endl;
}

class Date {
public:
    Date(int year, int month, int day)
            : _year(year), _month(month), _day(day) {}

    bool operator<(const Date &d) const {
        return _day < d._day;
    }

    bool operator>(const Date &d) const {
        return _day > d._day;
    }

    friend class Compare;

private:
    int _year;
    int _month;
    int _day;
};


// 仿函数--函数对象：可以像函数一样使用的对象
class Compare {
public:
    bool operator()(const Date *left, const Date *right) {
        return left->_day < right->_day;
    }
};

void TestPriorityQueue3() {
    priority_queue<Date *, vector<Date *>, Compare> q;

    Date d1(2023, 4, 22);
    Date d2(2023, 4, 21);
    Date d3(2023, 4, 23);

    q.push(&d1);
    q.push(&d2);
    q.push(&d3);
}

//int main()
//{
//    // TestPriorityQueue1();
//    // TestPriorityQueue2();
//    TestPriorityQueue3();
//    return 0;
//}

int main() {
    return 0;
}
